//
//  WYStatusRetweetedView.swift
//  weibo
//
//  Created by 王玉东 on 16/4/13.
//  Copyright © 2016年 wyd. All rights reserved.
//

import UIKit
import SnapKit
class WYStatusRetweetedView: UIView {
    var bottomCons:Constraint?
    var statusModel: WYStatusModel? {
        didSet{
        
            contentLable.text = statusModel?.status?.retweeted_status?.text
            
            
            self.bottomCons?.uninstall()
            if let urls = statusModel?.status?.retweeted_status?.pic_urls where urls.count > 0 {
            self.snp_updateConstraints(closure: { (make) -> Void in
                self.bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
            })
                pictureView.imageURLs = urls
                pictureView.hidden = false
            
            }else{
            
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomCons = make.bottom.equalTo(contentLable.snp_bottom).offset(StatusCellMargin).constraint
                })
                pictureView.imageURLs = nil

                pictureView.hidden = true
            }
            
        
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setUI(){
    
            backgroundColor = UIColor(white: 0.9, alpha: 1)
        
            addSubview(contentLable)
            addSubview(pictureView)
        
            contentLable.numberOfLines = 0
        
            contentLable.snp_makeConstraints { (make) -> Void in
                make.top.left.equalTo(self).offset(StatusCellMargin)
        }
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLable.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(contentLable.snp_left)
        }
        
    self.snp_makeConstraints { (make) -> Void in
       self.bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        make.width.equalTo(200)
        
        }
    
    
    }
   
    private lazy var contentLable: UILabel = UILabel(text: "转发微博", fontSize: 15, textColor: UIColor.darkGrayColor(), margin: 8)
    private lazy var pictureView : WYStatusPictureView = WYStatusPictureView()
}
